package com.example.forum_system.dao;

import com.example.forum_system.model.Message;
import com.example.forum_system.model.VO.MessageVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MessageMapper {

    //1.新增站内信消息
    @Insert("insert into t_message(postUserId, receiveUserId, content, state, deleteState, createTime, updateTime) values (#{postUserId}, #{receiveUserId}, #{content}, #{state}, #{deleteState}, #{createTime}, #{updateTime})")
    int insertMessage(Message message);

    //2.获取所有站内信列表,根据接收者id
    @Select("select * from t_message where (deleteState=0 and receiveUserId=#{receiveUserId}) order by state asc")
    List<MessageVO> selectAllMessage(@Param("receiveUserId") long receiveUserId);

    //3.获取未阅读站内信的总数,根据接收者id
    @Select("select COUNT(id) from t_message where state=0 and deleteState=0 and receiveUserId=#{receiveUserId}")
    int selectUnreadCount(@Param("receiveUserId")long receiveUserId);

    //4.修改站内信状态,所有未读消息变已读,根据接收者id
    @Update("update t_message set state=1 where state=0 and receiveUserId=#{receiveUserId}")
    int updateStateToRead(@Param("receiveUserId")long receiveUserId);

    //5.修改站内信状态,状态改为已回复,根据站内信id
    @Update("update t_message set state=2 where id=#{id}")
    int updateStateToReplied(@Param("id")long id);

//    int insert(Message row);
//
//    int insertSelective(Message row);
//
//    Message selectByPrimaryKey(Long id);
//
//    int updateByPrimaryKeySelective(Message row);
//
//    int updateByPrimaryKey(Message row);
}